<?php
declare (strict_types = 1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\api\model\RolesPolicyRelation as RolesPolicyRelationModel;

class RolesPolicyRelation extends Base
{

    /**
     * 角色规则绑定关系列表
     * @param $page
     * @param $pagesize
     * @return \think\response\Json
     */
    public function rolespolicylist($page,$pagesize){
        try {
            $RolesPolicyRelationModel = new RolesPolicyRelationModel();
            $list = $RolesPolicyRelationModel->RolesPolicyList($page,$pagesize);
            return json($list);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 新增角色规则绑定关系
     * @param $roles_id
     * @param $policy_id
     * @param int $status
     * @return \think\response\Json
     */
    public function rolespolicyadd($roles_id,$policy_id,$status=1){
        try {
            $RolesPolicyRelationModel = new RolesPolicyRelationModel();
            $res = $RolesPolicyRelationModel->RolesPolicyAdd($roles_id,$policy_id,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 保存角色
     * @param $roles_id
     * @param $rolesname
     * @param $exp_time
     * @return \think\response\Json
     */
    public function rolespolicyedit($roles_id,$rolesname,$exp_time){
        try {
            $RolesPolicyRelationModel = new RolesPolicyRelationModel();
            $res = $RolesPolicyRelationModel->RolesPolicyEdit($id,$roles_id,$policy_id);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 角色启/禁用
     * @param $roles_id
     * @param $status
     * @return \think\response\Json
     */
    public function rolessetstatus($roles_id,$status){
        try {
            $RolesModel = new RolesModel();
            $res = $RolesModel->RolesSetStatus($roles_id,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 角色删除
     * @param $roles_id
     * @return \think\response\Json
     */
    public function rolesdel($roles_id){
        try {
            $RolesModel = new RolesModel();
            $res = $RolesModel->RolesDel($roles_id);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

}
